<template>
	<view class="goUseCoupon">
		<view class="goods-list" >
			<view v-for="item in skuList" :key="item.skuId" class="goods-item" @click="navToDetailPage(item)">
				<image :src="item.skuDefaultImg == null || item.skuDefaultImg == ''?item.imgUrl:item.skuDefaultImg" mode="widthFix" class="sku-img"></image>
				<text class="title">{{ item.skuName }}</text>
				<view class="price-box">
					<text class="price">{{ item.price }}</text>
					<text>已售 {{ item.saleCount }}</text>
				</view>
			</view>
		</view>
		<uni-load-more :status="skuLoadType"></uni-load-more>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				skuList: [],
				pageNum: 1,
				total: 0,
				skuLoadType: false,
			}
		},
		onLoad(e) {
			console.log(e.id);
			// 根据优惠券 id 获取可使用的商品列表
			// this.$api.request.getSkuByIdList({
			// 	couponId: e.id
			// }, res => {
			// 	if (res.code == 200) {
			// 		this.skuList = res.data
			// 	}
			// })
			this.getSkuList()
			
		},
		//加载更多
		onReachBottom() {
			console.log(this.total);
			console.log(this.pageNum * 10);
			if(this.total >= this.pageNum * 10){
				this.pageNum += 1
				this.getSkuList()
			}else{
				this.skuLoadType = true
			}
		},
		methods: {
			// 获取数据
			getSkuList(){
				this.$api.request.getShopSkuList({
					pageNum: this.pageNum,
					shopId: "1546776383826657282",
					searchVal: ''
				}, res => {
					if(res.code == 200){
						this.total = res.data.total
						this.skuList = [...this.skuList, ...res.data.records]
					}
				})
			},
			//导航到商品详情页
			navToDetailPage(item) {
				uni.navigateTo({
					url: '/pages/sys/home/product?id=' + item.skuId
				})
			}
		}
	}
</script>

<style lang="scss">
	// .goUseCoupon {
	// 	width: 100vw;
	// 	height: 100vh;
	// 	overflow-y: scroll;
	// }

	/* 商品列表 */
	.goods-list {
		column-count: 2;
		column-gap: 20rpx;
		padding: 20rpx;

		.goods-item {
			break-inside: avoid;
			width: 100%;
			height: 100%;
			display: flex;
			padding-bottom: 10rpx;
			border-radius: 15rpx;
			margin-bottom: 30rpx;
			flex-direction: column;
			background-color: #FFFFFF;
			box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.05);

			&:nth-child(2n+1) {
				margin-right: 2%;
			}

			.sku-img {
				width: 100%;
				height: 100%;
				min-height: 300rpx;
				border-top-left-radius: 20rpx;
				border-top-right-radius: 20rpx;
			}

			.title {
				color: #000000;
				font-weight: bold;
				font-size: 26rpx;
				line-height: 32rpx;
				margin: 12rpx 0;
				margin-left: 20rpx;
			}

			.price-box {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-right: 10rpx;
				font-size: 24rpx;
				color: $font-color-light;
				margin-left: 20rpx;
			}

			.price {
				font-size: $font-lg;
				color: $uni-color-primary;
				line-height: 1;

				&:before {
					content: '￥';
					font-size: 26rpx;
				}
			}
		}
	}
</style>
